package com.nan.controller;

import com.nan.model.Student;
import com.nan.model.Teacher;
import com.nan.dto.StudentTeacherDTO;
import com.nan.service.ClassService;
import com.nan.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LittleY
 * @date 2025/6/9
 * @description 学生管理控制器
 */
@Tag(name = "学生管理", description = "学生信息的增删改查接口")
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private ClassService classService;


    /**
     * 根据ID查询学生信息
     * @param id 学生ID
     * @return 学生信息
     */
    @Operation(summary = "根据ID查询学生信息", description = "根据学生ID获取单个学生的详细信息")
    @GetMapping("/{id}")
    public Student getById(@Parameter(description = "学生ID") @PathVariable("id") Long id) {
        return studentService.getById(id);
    }

    /**
     * 查询所有学生信息
     * @return 学生列表
     */
    @Operation(summary = "查询所有学生信息", description = "获取所有学生的列表信息")
    @GetMapping
    public List<Student> list() {
        return studentService.list();
    }

    /**
     * 新增学生信息
     * @param student 学生信息
     * @return 是否成功
     */
    @Operation(summary = "新增学生信息", description = "添加一个新的学生信息")
    @PostMapping
    public boolean save(@Parameter(description = "学生信息") @RequestBody Student student) {
        return studentService.save(student);
    }

    /**
     * 更新学生信息
     * @param student 学生信息
     * @return 是否成功
     */
    @Operation(summary = "更新学生信息", description = "根据学生ID更新学生信息")
    @PutMapping
    public boolean update(@Parameter(description = "学生信息") @RequestBody Student student) {
        return studentService.updateById(student);
    }

    /**
     * 删除学生信息
     * @param id 学生ID
     * @return 是否成功
     */
    @Operation(summary = "删除学生信息", description = "根据学生ID删除学生信息")
    @DeleteMapping("/{id}")
    public boolean delete(@Parameter(description = "学生ID") @PathVariable("id") Long id) {
        return studentService.removeById(id);
    }

    /**
     * 根据学生ID查询对应的教师列表
     * @param id 学生ID
     * @return 教师列表
     */
    @Operation(summary = "查询学生对应的教师列表", description = "根据学生ID获取对应的教师列表信息")
    @GetMapping("/{id}/with-teacher")
    public List<Teacher> getTeachersByStudentId(@Parameter(description = "学生ID") @PathVariable("id") Long id) {
        return studentService.getTeachersByStudentId(id);
    }

    @Operation(summary = "查询对应学生信息", description = "根据班级ID查询对应学生信息")
    @GetMapping("/getStudentByClassId/{id}")
    public List<Student> findStudentByClassId(@Parameter(description = "班级ID") @PathVariable("id") Long id) {
        return classService.queryStudentByClassId(id);
    }

    @Operation(summary = "查询班级组信息", description = "根据班级ID查询班级组信息")
    @GetMapping("/getGroupByClassId/{id}")
    public List<Integer> getGroupByClassId(@Parameter(description = "班级ID") @PathVariable("id") Long id) {
        return studentService.queryGroupByClassId(id);
    }

    @Operation(summary = "查询学生信息", description = "根据班级id和group查询学生信息")
    @GetMapping("/getStudentByClassIdAndGroup/{classId}/{group}")
    public List<Student> getStudentByClassIdAndGroup(@Parameter(description = "班级ID") @PathVariable("classId") Long classId, @Parameter(description = "组号") @PathVariable("group") Integer group) {
        return studentService.getStudentByClassIdAndGroup(classId, group);
    }

}
